def transfer(self, from_card_id, to_card_id, amount, password, remark=None):
    """执行转账操作"""
    # 确保数据库连接有效
    if not self.db.connect():
        return False, "无法连接到数据库"

    if not isinstance(amount, (int, float)) or amount <= 0:
        return (False, "转账金额必须为正数")

    if from_card_id == to_card_id:
        return (False, "不能向自己转账")

    if not self.db.connect():
        return (False, "无法连接到数据库")

    try:
        # 1. 验证转出卡信息
        from_card_query = """
        SELECT balance, pass, IsReportLoss 
        FROM cardInfo 
        WHERE cardID = %s 
        """
        from_card_info = self.db.execute_query(from_card_query, (from_card_id,))

        if not from_card_info or len(from_card_info) == 0:
            return (False, "转出卡不存在")

        from_card_info = from_card_info[0]

        if from_card_info['IsReportLoss'] == '是':
            return (False, "转出卡已挂失")

        if from_card_info['pass'] != password:
            return (False, "转出卡密码错误")

        if from_card_info['balance'] < amount:
            return (False, "转出卡余额不足")

        # 2. 验证转入卡信息
        to_card_query = """
        SELECT IsReportLoss 
        FROM cardInfo 
        WHERE cardID = %s 
        """
        to_card_info = self.db.execute_query(to_card_query, (to_card_id,))

        if not to_card_info or len(to_card_info) == 0:
            return (False, "转入卡不存在")

        to_card_info = to_card_info[0]

        if to_card_info['IsReportLoss'] == '是':
            return (False, "转入卡已挂失")

        # 3. 执行转账操作
        trade_id = self._generate_trade_id()

        # 转出卡扣款
        update_from_query = """
        UPDATE cardInfo 
        SET balance = balance - %s 
        WHERE cardID = %s
        """
        if not self.db.execute_query(update_from_query, (amount, from_card_id), fetch=False):
            return (False, "转出卡更新失败")

        # 转入卡加款
        update_to_query = """
        UPDATE cardInfo 
        SET balance = balance + %s 
        WHERE cardID = %s
        """
        if not self.db.execute_query(update_to_query, (amount, to_card_id), fetch=False):
            return (False, "转入卡更新失败")

        # 记录转出交易
        insert_out_query = """
        INSERT INTO tradeInfo 
        (cardID, tradeDate, tradeType, transactionID, tradeMoney, remark)
        VALUES (%s, NOW(), '转账转出', %s, %s, %s)

        """
        if not self.db.execute_query(
                insert_out_query,
                (from_card_id, trade_id, -amount, remark),
                fetch=False
        ):
            return (False, "转出交易记录失败")

        # 记录转入交易
        insert_in_query = """
        INSERT INTO tradeInfo 
        (cardID, tradeDate, tradeType, transactionID, tradeMoney, remark)
        VALUES (%s, NOW(), '转账转入', %s, %s, %s)
        """
        if not self.db.execute_query(
                insert_in_query,
                (to_card_id, trade_id, amount, remark),
                fetch=False
        ):
            return (False, "转入交易记录失败")

        # 确保所有操作成功
        return (True, f"成功转账 ¥{amount:.2f} 到卡号 {to_card_id}")

    except Exception as e:
        print(f"转账失败: {e}")
        return (False, f"转账失败: {str(e)}")